
/***********************************************************************************************************************
**                                                    Includes                                                        **
***********************************************************************************************************************/
#include "Rte.h"
#include "Cdd_Mcal.h"
#include "Com.h"
#include "CanTp.h"
#include "Diag.h"

/***********************************************************************************************************************
**                                           Global Variable Definitions                                              **
***********************************************************************************************************************/


/***********************************************************************************************************************
**                                            Private Macro Definitions                                               **
***********************************************************************************************************************/


/***********************************************************************************************************************
**                                            Private Type Definitions                                                **
***********************************************************************************************************************/


/***********************************************************************************************************************
**                                           Private Variable Definitions                                             **
***********************************************************************************************************************/
/* 初始化完成标志，默认未完成初始化 */
static uint8 initFinishState = 1;

/*Did data*/
static uint8 Rte_Appl_DidData_F190[17];
static uint8 Rte_Bsw_DidData_F190[17];
static boolean Rte_Bsw_DidData_F190_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0301[1];
static uint8 Rte_Appl_DidData_0302[2];
static uint8 Rte_Appl_DidData_0303[2];
static uint8 Rte_Appl_DidData_0304[2];
static uint8 Rte_Appl_DidData_0305[2];
static uint8 Rte_Appl_DidData_0306[2];
static uint8 Rte_Appl_DidData_0307[2];
static uint8 Rte_Appl_DidData_0308[2];
static uint8 Rte_Appl_DidData_0309[1];
static uint8 Rte_Appl_DidData_0310[1];
static uint8 Rte_Appl_DidData_0311[1];
static uint8 Rte_Appl_DidData_0312[1];
static uint8 Rte_Appl_DidData_0313[1];
static uint8 Rte_Appl_DidData_0314[1];
static uint8 Rte_Appl_DidData_0315[1];
static uint8 Rte_Appl_DidData_0316[1];
static uint8 Rte_Appl_DidData_0317[2];
static uint8 Rte_Appl_DidData_0318[1];
static uint8 Rte_Appl_DidData_0319[1];
static uint8 Rte_Appl_DidData_0320[1];
static uint8 Rte_Appl_DidData_0321[2];
static uint8 Rte_Bsw_DidData_0321[2];
static boolean Rte_Bsw_DidData_0321_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0322[2];
static uint8 Rte_Bsw_DidData_0322[2];
static boolean Rte_Bsw_DidData_0322_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0323[2];
static uint8 Rte_Bsw_DidData_0323[2];
static boolean Rte_Bsw_DidData_0323_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0324[2];
static uint8 Rte_Bsw_DidData_0324[2];
static boolean Rte_Bsw_DidData_0324_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0325[2];
static uint8 Rte_Bsw_DidData_0325[2];
static boolean Rte_Bsw_DidData_0325_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0326[2];
static uint8 Rte_Appl_DidData_0327[2];
static uint8 Rte_Appl_DidData_0328[2];
static uint8 Rte_Appl_DidData_0329[2];
static uint8 Rte_Appl_DidData_0330[1];
static uint8 Rte_Appl_DidData_0331[4];
static uint8 Rte_Bsw_DidData_0331[4];
static boolean Rte_Bsw_DidData_0331_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0332[7];
static uint8 Rte_Appl_DidData_0333[1];
static uint8 Rte_Appl_DidData_0334[1];
static uint8 Rte_Appl_DidData_0335[1];
static uint8 Rte_Appl_DidData_0336[2];
static uint8 Rte_Appl_DidData_0337[3];
static uint8 Rte_Bsw_DidData_0337[3];
static boolean Rte_Bsw_DidData_0337_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0338[1];
static uint8 Rte_Appl_DidData_0339[1];
static uint8 Rte_Bsw_DidData_0339[1];
static boolean Rte_Bsw_DidData_0339_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0340[2];
static uint8 Rte_Bsw_DidData_0340[2];
static boolean Rte_Bsw_DidData_0340_Invalid = FALSE;
static uint8 Rte_Appl_DidData_0341[1];
static uint8 Rte_Bsw_DidData_0341[1];
static boolean Rte_Bsw_DidData_0341_Invalid = FALSE;

/*诊断仪控制有效标记，TRUE表示控制权在诊断仪，FALSE表示控制权在ASW*/
static boolean Rte_Diag_IOCtrl_3031_TesterValid = FALSE;
static boolean Rte_Diag_IOCtrl_3032_TesterValid = FALSE;
static boolean Rte_Diag_IOCtrl_3033_TesterValid = FALSE;


/***********************************************************************************************************************
**                                           Private Function Declarations                                            **
***********************************************************************************************************************/

/***********************************************************************************************************************
**                                                  Global Functions                                                  **
***********************************************************************************************************************/
extern void bms_Slave_step(void);
extern void bms_Slave_initialize(void);

/***********************************************************************************************************************
**                                            Global Function Definitions                                             **
***********************************************************************************************************************/

/**
  * @brief  任务初始化
  * @param  None
  * @retval None
  */
void Task_Init(void)
{
    Cdd_McalInit();    
    Com_Init();
	CanTp_Init();
    Diag_Init();
	/* 初始化完成 */
    initFinishState = 0;
    /*do not change the order*/
    bms_Slave_initialize();
}

/**
  * @brief  1ms任务
  * @param  None
  * @retval None
  */
void Task_1ms(void)
{  
    /* nop */
}

/**
  * @brief  5ms任务
  * @param  None
  * @retval None
  */
void Task_5ms(void)
{
    Cdd_Task_5ms();
}

/**
  * @brief  10ms任务
  * @param  None
  * @retval None
  */
void Task_10ms(void)
{
    Cdd_Task_10ms();
    Com_MessageTimeout();
    CanTp_MainFunction();
    bms_Slave_step();
}

/**
  * @brief  50ms任务
  * @param  None
  * @retval None
  */
void Task_50ms(void)
{
    Diag_MainFunction();
}

/**
  * @brief  100ms任务
  * @param  None
  * @retval None
  */
void Task_100ms(void)
{
    Cdd_Task_100ms();
}

/**
  * @brief  空闲任务
  * @param  None
  * @retval None
  */
void Task_Idle(void)
{
    Com_MainFunction();
    Cdd_Task_Idle();
}

/***********************************************************************************************************************
**                                    Rte Interface, Called by ASW.                                                   **
***********************************************************************************************************************/
/**
  * @brief  读取电池单体电压
  * @param  单体电池的ID，范围：0-31
  * @retval 指定ID的电池电压采样值，范围0-65535，换算公式：V=R*(5/32),单位：mV
  */
uint16 Rte_Read_CellV_IN(uint8 id)
{
    AFE_Info_Type* info;
    uint16 retValue = 0;
    
    if (id <= 14)
    {
        info = Afe_GetAfeInfo(0);
        retValue = info->VCell[id];
    }
    else if((16 <= id) && (id <= 27))
    {
        //info = Afe_GetAfeInfo(1);
        retValue = 0;//info->VCell[id-16];
    }
    
    return retValue;
}

/**
  * @brief  读取单体温度，包括AFE芯片读取的温度（ID范围:0-5）+MCU读取的温度(ID范围:6-11）
  * @param  采样温度的ID，范围：0-11；ID0-2：分别对应AFE1的T3、T2、T1；
									  ID3-5：分别对应AFE2的T2、T3、T1；
									  ID6-9:分别对应AFE1_NTC4,AFE1_NTC5,AFE2_NTC4,AFE2_NTC5
									  其它预留。
  * @retval 指定ID的温度采样值；
            AFE：范围0-65535，换算公式：电阻=(R/(32768-R))*Ref（Ref通过Rte_Read_Temp_Ref接口获取）,单位：kΩ；
            MCU：范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_CellT_AD_IN(uint8 id)
{
    AFE_Info_Type* info;
    uint16 retValue = 0;
    
    if (id <= 2)
    {
        info = Afe_GetAfeInfo(0);
        retValue = info->TCell[id];
    }
    else if((3 <= id) && (id <= 5))
    {
        //info = Afe_GetAfeInfo(1);
        retValue = 0;//info->TCell[id-3];
    }
    else if (id == 6)
	{
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
		AdcDriver_GetAdcSampleValue(AFE1_NTC4_AD, &retValue);
#else    
		AdcDriver_GetAdcFilterResult(AFE1_NTC4_AD, &retValue);
#endif 
	}
	else if (id == 7)
	{
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
		AdcDriver_GetAdcSampleValue(AFE1_NTC5_AD, &retValue);
#else    
		AdcDriver_GetAdcFilterResult(AFE1_NTC5_AD, &retValue);
#endif 
	}
	else if (id == 8)
	{
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
		//AdcDriver_GetAdcSampleValue(AFE2_NTC4_AD, &retValue);
#else    
		//AdcDriver_GetAdcFilterResult(AFE2_NTC4_AD, &retValue);
#endif 
	}
	else if (id == 9)
	{
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
		//AdcDriver_GetAdcSampleValue(AFE2_NTC5_AD, &retValue);
#else    
		//AdcDriver_GetAdcFilterResult(AFE2_NTC5_AD, &retValue);
#endif 
	}
	else
	{
		/* nop */
	}
    
    return retValue;
}

/**
  * @brief  读取温度参考值
  * @param  ID，AFE采样的温度ID范围：0-1；
  * @retval 范围0-127，换算公式：Ref=6.8+0.05*R，单位：kΩ
  */
uint16 Rte_Read_Temp_Ref(uint8 channel)
{    
    AFE_Info_Type* info;
	
    if (channel  == 0)
    {
        info = Afe_GetAfeInfo(0);
    }
    else if (channel == 1)
    {
        info = Afe_GetAfeInfo(0);
    }
    else
    {
        /* nop */
    }
    
    return (uint16)info->CTR;
}

/**
  * @brief  读取单体电压采样的有效性
  * @param  无
  * @retval 范围0-1，0：有效，1：无效
  */
uint8 Rte_Read_CellV_Valid(void)
{
    return (Afe_GetAfeInfo(0)->Alive);//| Afe_GetAfeInfo(1)->Alive);
}

/**
  * @brief  读取单体温度采样的有效性
  * @param  无
  * @retval 范围0-1，0：有效，1：无效
  */
uint8 Rte_Read_CellT_Valid(void)
{
    return (Afe_GetAfeInfo(0)->Alive);// | Afe_GetAfeInfo(1)->Alive);
}

/**
  * @brief  读取均衡通道状态
  * @param  无
  * @retval bit0表示第一个单体，bit31表示最后单体，实际有效就是bit0-11，bit16-27。
            0表示不均衡，1表示均衡
  */
uint32 Rte_Read_Balance_State(void)
{
	uint32 state;
    uint8 ret;
    ret = AFE_ReadBalance(&state);
	if (0 != ret) //0:succes
	{
		state = 0;
	}
    return state;
}

/**
  * @brief  发送均衡通道命令
  * @param  state: bit0~15 = afe1, bit16~31 = afe2
            bit0表示第一个单体，bit31表示最后单体，实际有效就是bit0-11，bit16-27。
            0表示不均衡，1表示均衡
  * @retval 无
  */
void Rte_Write_Balance_Cmd(uint32 state)
{
    AFE_BalanceCtrl(state);
}

/**
  * @brief  读取放电MOS状态
  * @param  无
  * @retval 范围0-1，0：OFF，1：ON
  */
uint8 Rte_Read_DischrgMOS_State(void)
{
    return AFE_ReadInfo(DSG);
}

/**
  * @brief  读取充电MOS状态
  * @param  无
  * @retval 范围0-1，0：OFF，1：ON
  */
uint8 Rte_Read_ChrgMOS_State(void)
{
    return AFE_ReadInfo(CHG);
}

/**
  * @brief  读取电池电压
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V；（需要根据分压电阻再次换算一次得到真实的电池电压）
  */
uint16 Rte_Read_BatVol(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(VB_72V_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(VB_72V_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取分流器AD值
  * @param  无
  * @retval xxx
  */
uint16 Rte_Read_Current_Shut_AD(uint8 channel)
{
	AFE_Info_Type* info;
	uint16 ret;
    
    if (channel  == 0)
    {
        info = Afe_GetAfeInfo(0);
		ret = (uint16)(info->CCell);
    }
    else if (channel == 1)
    {
        info = Afe_GetAfeInfo(0);
		ret = (uint16)(info->CCell);
    }
	else
	{
		ret = 0;
	}
    
    return ret;
}

/**
  * @brief  读取电流效性
  * @param  无
  * @retval xxx
  */
uint8 Rte_Read_Current_Valid(void)
{
    return (Afe_GetAfeInfo(0)->Alive);// | Afe_GetAfeInfo(1)->Alive);
}

/**
  * @brief  读取初始化状态
  * @param  无
  * @retval 范围0-1，0：初始化完成，1：初始化未完成
  */
uint8 Rte_Read_INI_Finish_flg(void)
{
    return initFinishState;
}

/**
  * @brief  读取PCB温度
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_PCB_AD_R(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(PACK_ID_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(PACK_ID_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取充电座正极温度
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_ChrgPos_AD_R(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(AFE1_NTC6_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(AFE1_NTC6_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取充电座负极温度
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_ChrgNeg_AD_R(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(AFE2_NTC6_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(AFE2_NTC6_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取ICU报文是否丢失
  * @param  无
  * @retval 范围0-1，0：未丢失，1：丢失
  */
uint8 Rte_Read_ICU_lost_flg(void)
{
	uint8 timeoutResult = 1;
		
    if (FALSE == Com_GetICUMessageTimeoutFlag())
    {
        timeoutResult = 0;
    }
	
	return timeoutResult;
}

/**
  * @brief  读取TBOX报文是否丢失
  * @param  无
  * @retval 范围0-1，0：未丢失，1：丢失
  */
uint8 Rte_Read_TBOX_lost_flg(void)
{
	uint8 timeoutResult = 1;
		
    if (FALSE == Com_GetTBOXMessageTimeoutFlag())
    {
        timeoutResult = 0;
    }
	
	return timeoutResult;
}

/**
  * @brief  读取BCM报文是否丢失
  * @param  无
  * @retval 范围0-1，0：未丢失，1：丢失
  */
uint8 Rte_Read_BCM_lost_flg(void)
{
	uint8 timeoutResult = 1;
		
    if (FALSE == Com_GetBCMMessageTimeoutFlag())
    {
        timeoutResult = 0;
    }
	
	return timeoutResult;
}

/**
  * @brief  读取INV报文是否丢失
  * @param  无
  * @retval 范围0-1，0：未丢失，1：丢失
  */
uint8 Rte_Read_INV_lost_flg(void)
{
	uint8 timeoutResult = 1;
		
    if (FALSE == Com_GetINVMessageTimeoutFlag())
    {
        timeoutResult = 0;
    }
	
	return timeoutResult;
}

/**
  * @brief  读取OBC报文是否丢失
  * @param  无
  * @retval 范围0-1，0：未丢失，1：丢失
  */
uint8 Rte_Read_OBC_lost_flg(void)
{
	uint8 timeoutResult = 1;
		
    if (FALSE == Com_GetOBCMessageTimeoutFlag())
    {
        timeoutResult = 0;
    }
	
	return timeoutResult;
}

/**
  * @brief  读取ACAN是否BUSOFF
  * @param  无
  * @retval 范围0-1，0：未BUSOFF，1：BUSOFF；
  */
uint8 Rte_Read_ACAN_BUSOFF_flg(void)
{
	uint8 busoffResult = 1;
		
    if (FALSE == Com_GetACANBusoffFlag())
    {
        busoffResult = 0;
    }
	
	return busoffResult;
}

/**
  * @brief  读取CHCAN是否BUSOFF
  * @param  无
  * @retval 范围0-1，0：未BUSOFF，1：BUSOFF；
  */
uint8 Rte_Read_CHCAN_BUSOFF_flg(void)
{
	uint8 busoffResult = 1;
		
    if (FALSE == Com_GetCHCANBusoffFlag())
    {
        busoffResult = 0;
    }
	
	return busoffResult;
}

/**
  * @brief  读取分流器温度
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_Shunt_Temp_AD(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(NTC1_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(NTC1_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  设置AFE运行模式
  * @param  0：normal，1：idle，2：sleep
  * @retval 无
  */
void Rte_Write_AFE_RunMode(uint8 mode)
{
    AFE_SetMode((AFE_ModeType)mode);
}

/**
  * @brief  读取CC2
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_CC2_AD(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(CC2_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(CC2_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取A+
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_AP(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(A_POSITIVE_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(A_POSITIVE_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取互锁状态
  * @param  无
  * @retval 范围0-1，0：插接插件，1：插接插件
  */
uint8 Rte_Read_Interlock_State(void)
{
    uint8 state = 0;
    
    state = GpioDriver_GetInputState(SHUNT_MOS);
    
    return state;
}

/**
  * @brief  读取供电电压
  * @param  无
  * @retval 范围0-4095，换算公式：V=(R/4095)*3.3，单位：V
  */
uint16 Rte_Read_Supply_Vol(void)
{
    uint16 adcResult = 0;
    
/* ADC原始值 */
#if (IF_ADC_RESULT == PRIMITIVE_ADC_RESULT)  
    AdcDriver_GetAdcSampleValue(VCC_3V3_PR_AD, &adcResult);
#else    
    AdcDriver_GetAdcFilterResult(VCC_3V3_PR_AD, &adcResult);
#endif 
    
    return adcResult;
}

/**
  * @brief  读取放电MOS状态
  * @param  无
  * @retval 范围0-1，低电平：0，高电平：1
  */
uint8 Rte_Read_DisCharge_State(void)
{
	uint8 state = 0;
	
	state = GpioDriver_GetInputState(DiSCHARGE_STA);
	
	return state;
}

/**
  * @brief  读取插枪状态
  * @param  无
  * @retval 范围0-1，低电平：0，高电平：1
  */
uint8 Rte_Read_Charge_State(void)
{
	uint8 state = 0;
	
	state = GpioDriver_GetInputState(CHARGE_STA);
	
	return state;
}

/**
  * @brief  设置欠压阈值
  * @param  data 欠压值
  * @retval 范围0-255，欠压值=寄存器值*20mV
  */
void Rte_Write_UnderVoltageTh(uint8 data)
{
	 AFE_SetUV(data);
}

/**
  * @brief  放电MOS控制
  * @param  范围0-1，0：OFF，1：ON
  * @retval 无
  */
void Rte_Write_DisChrg_MOS_Control(uint8 cmd)
{
    /*FALSE表示控制权在ASW，该接口功能才有效*/
    if (FALSE == Rte_Diag_IOCtrl_3031_TesterValid)
    {
        AFE_MosfetCtrl(DSG, (boolean)cmd);
    }
}

/**
  * @brief  充电MOS控制
  * @param  范围0-1，0：OFF，1：ON
  * @retval 无
  */
void Rte_Write_Chrg_MOS_Control(uint8 cmd)
{
    /*FALSE表示控制权在ASW，该接口功能才有效*/
    if (FALSE == Rte_Diag_IOCtrl_3032_TesterValid)
    {
        AFE_MosfetCtrl(CHG, (boolean)cmd);
    }
}

/**
  * @brief  DC继电器控制
  * @param  范围0-1，0：OFF，1：ON
  * @retval 无
  */
void Rte_Write_DC_Contact_Control(uint8 cmd)
{
    /*FALSE表示控制权在ASW，该接口功能才有效*/
    if (FALSE == Rte_Diag_IOCtrl_3033_TesterValid)
    {
        GpioDriver_SetOutputState(CHARGE_RELAY_EN, cmd);
    }        
}

/**
  * @brief  放电过流保护状态
  * @param  channel AFE通道
  * @retval 范围0-1，0：未发生过流保护，1：发生过流保护
  */
uint8 Rte_Read_AFE_OCDSta(uint8 channel)
{
	AFE_Info_Type* info;
	if ( 0 == channel )
	{
		info = Afe_GetAfeInfo(0);
	}
	else
	{
		//info = Afe_GetAfeInfo(1);
	}
	 return info->OCD1Sta || info->OCD2Sta;
}

/**
  * @brief  充电过流保护状态
  * @param  channel AFE通道
  * @retval 范围0-1，0：未发生过流保护，1：发生过流保护
  */
uint8 Rte_Read_AFE_OCCSta(uint8 channel)
{
	AFE_Info_Type* info;
	if ( 0 == channel )
	{
		info = Afe_GetAfeInfo(0);
	}
	else
	{
		//info = Afe_GetAfeInfo(1);
	}
	 return info->OCCSta;
}



/**
  * @brief  读EEPROM数据
  * @param  p：读取数据待存放数组的首地址，len：读取长度（长度范围1-256）
  * @retval 读取结果，0：读取成功，1：读取失败
  */
uint8 Rte_Read_EEData(uint8 *p, uint16 len)
{
    return FlashDriver_ReadData(p, len); 
}

/**
  * @brief  写EEPROM数据，所有待存储数据一次性写入
  * @param  p：写入数据首地址，len：写入长度（长度范围1-256）
  * @retval 写入结果，0：写入成功，1：写入失败
  */
uint8 Rte_Write_EEData(uint8 *p, uint16 len)
{
    return FlashDriver_WriteData(p, len);
}



/**
  * @brief  接收CAN数据
  * @param  canx：CAN通道，0：ACAN，1：CHCAN；id：报文ID；data：报文数据；len：数据长度
  * @retval 接收结果，1：接收到新的报文，0：自上一次读取后未收到新的报文
  */
uint8 RTE_CAN_RecvCanDataById(uint8 canx, uint32 id, uint8* data, uint8* len)
{
    uint8 ret;
    if (0 == canx)
    {
        ret = Com_ReceiveCanData(COM_CHANNEL_ACAN, id, data, len);
    }
    else if (1u == canx)
    {
        ret = Com_ReceiveCanData(COM_CHANNEL_CHCAN, id, data, len);
    }
    else
    {
        ret = FALSE;
    }
    return ret;
}

/**
  * @brief  发送CAN数据
  * @param  canx：CAN通道，0：ACAN，1：CHCAN；id：报文ID；data：报文数据；len：数据长度
  * @retval 无
  */
void RTE_CAN_SendCanDataById(uint8 canx, uint32 id, uint8* data, uint8 Len)
{
    if (0 == canx)
    {
        Com_SendCanData(COM_CHANNEL_ACAN, id, data, Len);
    }
    else if (1u == canx)
    {
        Com_SendCanData(COM_CHANNEL_CHCAN, id, data, Len);
    }
    else
    {
    }
}


/**
  * @brief  读写DID
  * @param  p 数据指针； len 数据长度
  * @retval 无
  */
void Rte_Send_DID_F190(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_F190[i] = p[i];
    }
}

uint8 Rte_Get_DID_F190(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_F190_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_F190[i];
        }
        Rte_Bsw_DidData_F190_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0301(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0301[i] = p[i];
    }
}

void Rte_Send_DID_0302(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0302[i] = p[i];
    }
}

void Rte_Send_DID_0303(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0303[i] = p[i];
    }
}

void Rte_Send_DID_0304(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0304[i] = p[i];
    }
}

void Rte_Send_DID_0305(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0305[i] = p[i];
    }
}

void Rte_Send_DID_0306(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0306[i] = p[i];
    }
}

void Rte_Send_DID_0307(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0307[i] = p[i];
    }
}

void Rte_Send_DID_0308(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0308[i] = p[i];
    }
}

void Rte_Send_DID_0309(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0309[i] = p[i];
    }
}

void Rte_Send_DID_0310(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0310[i] = p[i];
    }
}

void Rte_Send_DID_0311(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0311[i] = p[i];
    }
}

void Rte_Send_DID_0312(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0312[i] = p[i];
    }
}

void Rte_Send_DID_0313(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0313[i] = p[i];
    }
}

void Rte_Send_DID_0314(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0314[i] = p[i];
    }
}

void Rte_Send_DID_0315(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0315[i] = p[i];
    }
}

void Rte_Send_DID_0316(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0316[i] = p[i];
    }
}

void Rte_Send_DID_0317(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0317[i] = p[i];
    }
}

void Rte_Send_DID_0318(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0318[i] = p[i];
    }
}

void Rte_Send_DID_0319(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0319[i] = p[i];
    }
}

void Rte_Send_DID_0320(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0320[i] = p[i];
    }
}

void Rte_Send_DID_0321(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0321[i] = p[i];
    }
}

uint8 Rte_Get_DID_0321(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0321_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0321[i];
        }
        Rte_Bsw_DidData_0321_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0322(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0322[i] = p[i];
    }
}

uint8 Rte_Get_DID_0322(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0322_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0322[i];
        }
        Rte_Bsw_DidData_0322_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0323(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0323[i] = p[i];
    }
}

uint8 Rte_Get_DID_0323(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0323_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0323[i];
        }
        Rte_Bsw_DidData_0323_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0324(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0324[i] = p[i];
    }
}

uint8 Rte_Get_DID_0324(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0324_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0324[i];
        }
        Rte_Bsw_DidData_0324_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0325(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0325[i] = p[i];
    }
}

uint8 Rte_Get_DID_0325(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0325_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0325[i];
        }
        Rte_Bsw_DidData_0325_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0326(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0326[i] = p[i];
    }
}

void Rte_Send_DID_0327(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0327[i] = p[i];
    }
}

void Rte_Send_DID_0328(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0328[i] = p[i];
    }
}

void Rte_Send_DID_0329(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0329[i] = p[i];
    }
}

void Rte_Send_DID_0330(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0330[i] = p[i];
    }
}

void Rte_Send_DID_0331(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0331[i] = p[i];
    }
}

uint8 Rte_Get_DID_0331(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0331_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0331[i];
        }
        Rte_Bsw_DidData_0331_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0332(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0332[i] = p[i];
    }
}

void Rte_Send_DID_0333(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0333[i] = p[i];
    }
}

void Rte_Send_DID_0334(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0334[i] = p[i];
    }
}

void Rte_Send_DID_0335(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0335[i] = p[i];
    }
}

void Rte_Send_DID_0336(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0336[i] = p[i];
    }
}

void Rte_Send_DID_0337(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0337[i] = p[i];
    }
}

uint8 Rte_Get_DID_0337(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0337_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0337[i];
        }
        Rte_Bsw_DidData_0337_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0338(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0338[i] = p[i];
    }
}

void Rte_Send_DID_0339(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0339[i] = p[i];
    }
}

uint8 Rte_Get_DID_0339(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0339_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0339[i];
        }
        Rte_Bsw_DidData_0339_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0340(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0340[i] = p[i];
    }
}

uint8 Rte_Get_DID_0340(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0340_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0340[i];
        }
        Rte_Bsw_DidData_0340_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}

void Rte_Send_DID_0341(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Appl_DidData_0341[i] = p[i];
    }
}

uint8 Rte_Get_DID_0341(uint8 *p, uint8 len)
{
    uint8 i;
    uint8 ret = 0; /*0-数据无效，1-数据有效*/
    if (TRUE == Rte_Bsw_DidData_0341_Invalid)
    {
        for (i = 0; i < len; i++)
        {
            p[i] = Rte_Bsw_DidData_0341[i];
        }
        Rte_Bsw_DidData_0341_Invalid = FALSE;
        ret = 1u;
    }
    return ret;
}



/***********************************************************************************************************************
**                                    Rte Interface, Called by BSW.                                                   **
***********************************************************************************************************************/
/*io control test. 0-Disable, 1-Enable, 2-invalid*/
void Rte_Diag_IOControl_Test(uint16 did, uint8 cmd)
{
    if (0x3031u == did)
    {
        if (2u != cmd)
        {
            Rte_Diag_IOCtrl_3031_TesterValid = TRUE;
            /*放电MOS控制，0：disable MOS； 1：enable*/
            AFE_MosfetCtrl(DSG, (boolean)cmd);
        }
        else
        {
            Rte_Diag_IOCtrl_3031_TesterValid = FALSE;
        }
    }
    else if (0x3032u == did)
    {
        if (2u != cmd)
        {
            Rte_Diag_IOCtrl_3032_TesterValid = TRUE;
            /*充电MOS控制，0：disable MOS； 1：enable*/
            AFE_MosfetCtrl(CHG, (boolean)cmd);
        }
        else
        {
            Rte_Diag_IOCtrl_3032_TesterValid = FALSE;
        }
    }
    else if (0x3033u == did)
    {
        if (2u != cmd)
        {
            Rte_Diag_IOCtrl_3033_TesterValid = TRUE;
            /*DC继电器控制，0：disable DC Relay； 1：enable DC Relay*/
            GpioDriver_SetOutputState(CHARGE_RELAY_EN, cmd);  
        }
        else
        {
            Rte_Diag_IOCtrl_3033_TesterValid = FALSE;
        }
    }
    else
    {
        /*do nothing*/
    }
}


/**
  * @brief  读写DID
  * @param  p 数据指针； len 数据长度
  * @retval 无
  */
void Rte_Diag_Read_DID_F187(uint8 *p, uint8 len)
{
    const uint8 ECUPartNumber[10] = {'D','K','0','0','6','0','0','1','0','0'};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = ECUPartNumber[i];
    }
}

void Rte_Diag_Read_DID_F188(uint8 *p, uint8 len)
{
    const uint8 ECUSoftwareNumber[10] = {'D','K','0','0','6','0','0','1','9','9'};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = ECUSoftwareNumber[i];
    }
}

void Rte_Diag_Read_DID_F18A(uint8 *p, uint8 len)
{
    const uint8 SupplierIdentifier[4] = {'K','0','0','1'};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = SupplierIdentifier[i];
    }
}

void Rte_Diag_Read_DID_F18C(uint8 *p, uint8 len)
{
    const uint8 ECUHardwareSerialNumber[11] = {1,2,3,4,5,6,7,8,9,10,11};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = ECUHardwareSerialNumber[i];
    }
}

void Rte_Diag_Read_DID_F190(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_F190[i];
    }
}

void Rte_Diag_Write_DID_F190(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_F190[i] = p[i];
    }
    Rte_Bsw_DidData_F190_Invalid = TRUE;
}

void Rte_Diag_Read_DID_F163(uint8 *p, uint8 len)
{
    const uint8 FlashDriverSoftwareNumber[10] = {1,2,3,4,5,6,7,8,9,10};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = FlashDriverSoftwareNumber[i];
    }
}

void Rte_Diag_Read_DID_F180(uint8 *p, uint8 len)
{
    const uint8 BootloaderSoftwareNumber[10] = {1,2,3,4,5,6,7,8,9,10};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = BootloaderSoftwareNumber[i];
    }
}

void Rte_Diag_Read_DID_F19E(uint8 *p, uint8 len)
{
    const uint8 ODXFileNumber[10] = {'V','0','2','_','2','2','0','7','0','8'};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = ODXFileNumber[i];
    }
}

void Rte_Diag_Read_DID_F194(uint8 *p, uint8 len)
{
    const uint8 ECUSoftwareSerialNumber[11] = {'B','M','S','2','3','0','3','0','1','2','2'};
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = ECUSoftwareSerialNumber[i];
    }
}

void Rte_Diag_Read_DID_0301(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0301[i];
    }
}

void Rte_Diag_Read_DID_0302(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0302[i];
    }
}

void Rte_Diag_Read_DID_0303(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0303[i];
    }
}

void Rte_Diag_Read_DID_0304(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0304[i];
    }
}

void Rte_Diag_Read_DID_0305(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0305[i];
    }
}

void Rte_Diag_Read_DID_0306(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0306[i];
    }
}

void Rte_Diag_Read_DID_0307(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0307[i];
    }
}

void Rte_Diag_Read_DID_0308(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0308[i];
    }
}

void Rte_Diag_Read_DID_0309(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0309[i];
    }
}

void Rte_Diag_Read_DID_0310(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0310[i];
    }
}

void Rte_Diag_Read_DID_0311(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0311[i];
    }
}

void Rte_Diag_Read_DID_0312(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0312[i];
    }
}

void Rte_Diag_Read_DID_0313(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0313[i];
    }
}

void Rte_Diag_Read_DID_0314(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0314[i];
    }
}

void Rte_Diag_Read_DID_0315(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0315[i];
    }
}

void Rte_Diag_Read_DID_0316(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0316[i];
    }
}

void Rte_Diag_Read_DID_0317(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0317[i];
    }
}

void Rte_Diag_Read_DID_0318(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0318[i];
    }
}

void Rte_Diag_Read_DID_0319(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0319[i];
    }
}

void Rte_Diag_Read_DID_0320(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0320[i];
    }
}

void Rte_Diag_Read_DID_0321(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0321[i];
    }
}

void Rte_Diag_Write_DID_0321(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0321[i] = p[i];
    }
    Rte_Bsw_DidData_0321_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0322(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0322[i];
    }
}

void Rte_Diag_Write_DID_0322(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0322[i] = p[i];
    }
    Rte_Bsw_DidData_0322_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0323(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0323[i];
    }
}

void Rte_Diag_Write_DID_0323(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0323[i] = p[i];
    }
    Rte_Bsw_DidData_0323_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0324(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0324[i];
    }
}

void Rte_Diag_Write_DID_0324(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0324[i] = p[i];
    }
    Rte_Bsw_DidData_0324_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0325(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0325[i];
    }
}

void Rte_Diag_Write_DID_0325(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0325[i] = p[i];
    }
    Rte_Bsw_DidData_0325_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0326(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0326[i];
    }
}

void Rte_Diag_Read_DID_0327(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0327[i];
    }
}

void Rte_Diag_Read_DID_0328(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0328[i];
    }
}

void Rte_Diag_Read_DID_0329(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0329[i];
    }
}

void Rte_Diag_Read_DID_0330(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0330[i];
    }
}

void Rte_Diag_Read_DID_0331(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0331[i];
    }
}

void Rte_Diag_Write_DID_0331(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0331[i] = p[i];
    }
    Rte_Bsw_DidData_0331_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0332(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0332[i];
    }
}

void Rte_Diag_Read_DID_0333(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0333[i];
    }
}

void Rte_Diag_Read_DID_0334(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0334[i];
    }
}

void Rte_Diag_Read_DID_0335(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0335[i];
    }
}

void Rte_Diag_Read_DID_0336(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0336[i];
    }
}

void Rte_Diag_Read_DID_0337(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0337[i];
    }
}

void Rte_Diag_Write_DID_0337(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0337[i] = p[i];
    }
    Rte_Bsw_DidData_0337_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0338(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0338[i];
    }
}

void Rte_Diag_Read_DID_0339(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0339[i];
    }
}

void Rte_Diag_Write_DID_0339(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0339[i] = p[i];
    }
    Rte_Bsw_DidData_0339_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0340(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0340[i];
    }
}

void Rte_Diag_Write_DID_0340(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0340[i] = p[i];
    }
    Rte_Bsw_DidData_0340_Invalid = TRUE;
}

void Rte_Diag_Read_DID_0341(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        p[i] = Rte_Appl_DidData_0341[i];
    }
}

void Rte_Diag_Write_DID_0341(uint8 *p, uint8 len)
{
    uint8 i;
    for (i = 0; i < len; i++)
    {
        Rte_Bsw_DidData_0341[i] = p[i];
    }
    Rte_Bsw_DidData_0341_Invalid = TRUE;
}


/*routine control:FF02,Check Programming Precondition*/
boolean Rte_Diag_CheckProgrammingPrecondition(void)
{
    return TRUE;
}


/**
  * @brief  CAN通道BusOff通知
  * @param  canBus：CAN通道，0：ACAN，1：CHCAN
  * @retval 无
  */
void Rte_Com_BusOffNotify(uint8 canBus)
{
    //TODO:
}

/**
  * @brief  CAN通道收到报文通知，每收到一帧报文通知一次
  * @param  canBus：CAN通道，0：ACAN，1：CHCAN
  *         canId：收到的报文ID
  * @retval 无
  */
void Rte_Com_RxMsgNotify(uint8 canBus, uint32 canId)
{
    //TODO:
}



/***********************************************************************************************************************
**                                           Private Function Definitions                                             **
***********************************************************************************************************************/


/***********************************************************************************************************************
**                                                  General Notes                                                     **
***********************************************************************************************************************/

